{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>question</th>\n",
       "      <th>answer</th>\n",
       "      <th>question_zh-cn</th>\n",
       "      <th>answer_only</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Natalia sold clips to 48 of her friends in Apr...</td>\n",
       "      <td>Natalia sold 48/2 = &lt;&lt;48/2=24&gt;&gt;24 clips in May...</td>\n",
       "      <td>纳塔利娅在 4 月份向 48 个朋友出售了视频片段，然后在 5 月份售出了一半的视频片段。娜...</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Weng earns $12 an hour for babysitting. Yester...</td>\n",
       "      <td>Weng earns 12/60 = $&lt;&lt;12/60=0.2&gt;&gt;0.2 per minut...</td>\n",
       "      <td>翁靠做保姆每小时挣 12 美元。昨天，她只做了 50 分钟的保姆工作。她赚了多少钱？</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Betty is saving money for a new wallet which c...</td>\n",
       "      <td>In the beginning, Betty has only 100 / 2 = $&lt;&lt;...</td>\n",
       "      <td>贝蒂正在攒钱买一个价值 100 美元的新钱包。贝蒂只有她需要的一半钱。她的父母决定为此给她 ...</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Julie is reading a 120-page book. Yesterday, s...</td>\n",
       "      <td>Maila read 12 x 2 = &lt;&lt;12*2=24&gt;&gt;24 pages today....</td>\n",
       "      <td>朱莉正在读一本 120 页的书。昨天，她能读12页，今天，她读的页数是昨天的两倍。如果她明天...</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>James writes a 3-page letter to 2 different fr...</td>\n",
       "      <td>He writes each friend 3*2=&lt;&lt;3*2=6&gt;&gt;6 pages a w...</td>\n",
       "      <td>詹姆斯每周两次给两个不同的朋友写一封三页的信。他一年写多少页？</td>\n",
       "      <td>624</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            question  \\\n",
       "0  Natalia sold clips to 48 of her friends in Apr...   \n",
       "1  Weng earns $12 an hour for babysitting. Yester...   \n",
       "2  Betty is saving money for a new wallet which c...   \n",
       "3  Julie is reading a 120-page book. Yesterday, s...   \n",
       "4  James writes a 3-page letter to 2 different fr...   \n",
       "\n",
       "                                              answer  \\\n",
       "0  Natalia sold 48/2 = <<48/2=24>>24 clips in May...   \n",
       "1  Weng earns 12/60 = $<<12/60=0.2>>0.2 per minut...   \n",
       "2  In the beginning, Betty has only 100 / 2 = $<<...   \n",
       "3  Maila read 12 x 2 = <<12*2=24>>24 pages today....   \n",
       "4  He writes each friend 3*2=<<3*2=6>>6 pages a w...   \n",
       "\n",
       "                                      question_zh-cn  answer_only  \n",
       "0  纳塔利娅在 4 月份向 48 个朋友出售了视频片段，然后在 5 月份售出了一半的视频片段。娜...           72  \n",
       "1         翁靠做保姆每小时挣 12 美元。昨天，她只做了 50 分钟的保姆工作。她赚了多少钱？           10  \n",
       "2  贝蒂正在攒钱买一个价值 100 美元的新钱包。贝蒂只有她需要的一半钱。她的父母决定为此给她 ...            5  \n",
       "3  朱莉正在读一本 120 页的书。昨天，她能读12页，今天，她读的页数是昨天的两倍。如果她明天...           42  \n",
       "4                    詹姆斯每周两次给两个不同的朋友写一封三页的信。他一年写多少页？          624  "
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df = pd.read_parquet('./gsm8k_chinese/data/train-00000-of-00001.parquet')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompts = []\n",
    "answers = []\n",
    "for question, answer in zip(df['question_zh-cn'], df['answer_only']):\n",
    "    SYSTEM = \"\"\"\n",
    "        按照如下格式回答问题：\n",
    "        <think>\n",
    "        你的思考过程\n",
    "        </think>\n",
    "        <answer>\n",
    "        你的回答\n",
    "        </answer>\n",
    "        \"\"\"\n",
    "        \n",
    "    \n",
    "    prompt = [\n",
    "            {\n",
    "                \"role\": \"system\",\n",
    "                \"content\": SYSTEM,\n",
    "            },\n",
    "            {\n",
    "                \"role\": \"user\",\n",
    "                \"content\": question,\n",
    "            }\n",
    "        ]\n",
    "    \n",
    "    prompts.append(prompt)\n",
    "    answers.append(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>prompt</th>\n",
       "      <th>answer</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[{'role': 'system', 'content': '\n",
       "        按照如下格...</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[{'role': 'system', 'content': '\n",
       "        按照如下格...</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[{'role': 'system', 'content': '\n",
       "        按照如下格...</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[{'role': 'system', 'content': '\n",
       "        按照如下格...</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[{'role': 'system', 'content': '\n",
       "        按照如下格...</td>\n",
       "      <td>624</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                              prompt  answer\n",
       "0  [{'role': 'system', 'content': '\n",
       "        按照如下格...      72\n",
       "1  [{'role': 'system', 'content': '\n",
       "        按照如下格...      10\n",
       "2  [{'role': 'system', 'content': '\n",
       "        按照如下格...       5\n",
       "3  [{'role': 'system', 'content': '\n",
       "        按照如下格...      42\n",
       "4  [{'role': 'system', 'content': '\n",
       "        按照如下格...     624"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_new = pd.DataFrame()\n",
    "df_new['prompt'] = prompts\n",
    "df_new['answer'] = answers\n",
    "df_new.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_new.to_parquet('./data_gsm8k/gsm8k_train.parquet')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "wyf",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
